package com.foreveredu.erlms.persist.hibernate;

import java.util.List;

import com.foreveredu.erlms.domain.Term;
import com.foreveredu.erlms.persist.ITermDao;

public class HibernateTermDao extends HibernateAbstractDao<Term, Integer>
		implements ITermDao {

	private static final long serialVersionUID = 1L;

	public HibernateTermDao() {
		super(Term.class);
	}

	@SuppressWarnings("unchecked")
	@Override
	public Term findTermOfNow() {
		List<Term> termList = this.getHibernateTemplate().find("from Term t where t.id = (select max(t.id) from t)");
		Term term = null;
		if (termList != null && termList.size() > 0) {
			term = termList.get(0);
		}
		return term;
	}

	@SuppressWarnings("unchecked")
	@Override
	public Term findTermByTimeAndOrder(int startYear, int endYear, int order) {
		List<Term> termList = this.getHibernateTemplate().find("from Term t where t.startYear = ? and t.endYear = ? and t.termOrder = ?", new Object[]{startYear, endYear, order});
		Term term = null;
		if (termList != null && termList.size() > 0) {
			term = termList.get(0);
		}
		return term;
	}

}
